package com.cj.service.impl;


import com.cj.dao.ClassDao;
import com.cj.po.Class;
import com.cj.po.PageInfo;
import com.cj.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service
@Transactional
public class ClassServiceImpl implements ClassService {

    // 注入studentDao
    @Autowired
    private ClassDao classDao;


    //分页查询
    @Override
    public PageInfo<Class> findPageInfo1(String c_classname, Integer c_id, Integer c_classid,
                                         String c_counsellor, Integer pageIndex, Integer pageSize) {
        PageInfo<Class> pi = new PageInfo<Class>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = classDao.totalCount(c_classname, c_id, c_classid, c_counsellor);
        if (totalCount > 0) {
            pi.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List classList1 = classDao.getClassList(c_classname, c_id, c_classid, c_counsellor,
                    (pi.getPageIndex() - 1) * pi.getPageSize(), pi.getPageSize());
            List<Class> classList = null;
            pi.setList(classList);
        }
        return pi;
    }

    @Override
    public int deleteClass(Integer c_id) {
        return classDao.deleteClass(c_id);
    }

    @Override
    public int addClass(Class cs) {
        return classDao.addClass(cs);
    }

    @Override
    public int updateClass(Class cs) {
        return classDao.updateClass(cs);
    }

    @Override
    public java.lang.Class findClassById(Integer c_id) {
        java.lang.Class s = classDao.findClassById(c_id);
        return s;
    }

    @Override
    public List<java.lang.Class> getAll() {
        List<java.lang.Class> classList = classDao.getAll();
        return classList;
    }
}